package com.servicesDirectory.action.contact;

import com.opensymphony.xwork2.ActionSupport;
import com.servicesDirectory.common.vo.BaseContactVO;
import com.servicesDirectory.dao.contact.BaseContactDAOImpl;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

public class ContactAction extends ActionSupport {

    private static final long serialVersionUID = 1251963794319720723L;
    protected BaseContactVO contact;
    protected LinkedList<BaseContactVO> contacts;
    private String nameSearch;
    private List<BaseContactVO> list;
    
    private String checkInclude;

    public String execute() {
        BaseContactDAOImpl bcDAO = new BaseContactDAOImpl();        
        bcDAO.setCheckInclude(checkInclude != null ? true : false);        
        this.list = bcDAO.search(contact);

        return SUCCESS;
    }
    public String addContact() throws ClassNotFoundException, SQLException{
    	BaseContactDAOImpl bcDAO = new BaseContactDAOImpl();        
    	
    	boolean result = bcDAO.insert(contact);
    	if(result)
    	{
        return SUCCESS;
    	}
    	else
		return "error";
    }
    @Override
    public void validate() {
    }

    public List<BaseContactVO> getList() {
        return list;
    }

    public void setList(List<BaseContactVO> list) {
        this.list = list;
    }

    public String getNameSearch() {
        return nameSearch;
    }

    public void setNameSearch(String nameSearch) {
        this.nameSearch = nameSearch;
    }

    public BaseContactVO getContact() {
        return contact;
    }

    public void setContact(BaseContactVO contact) {
        this.contact = contact;
    }

    public LinkedList<BaseContactVO> getContacts() {
        return contacts;
    }

    public void setContacts(LinkedList<BaseContactVO> contacts) {
        this.contacts = contacts;
    }

    public String getCheckInclude() {
        return checkInclude;
    }
    
    public void setCheckInclude(String checkInclude) {
        this.checkInclude = checkInclude;
    }
}
